

package com.zmks.jkgj.xuexiao.controller;




import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import com.zmks.jkgj.core.controller.ABaseController;
import com.zmks.jkgj.core.resp.Resp;
import com.zmks.jkgj.xuexiao.SessionManager;
import com.zmks.jkgj.xuexiao.resp.WebResp;

import com.zmks.jkgj.xuexiao.service.ICrctObjGradeService;

import com.zmks.jkgj.xuexiao.vo.CrctObjGradeVO;

/**
 * 年纪管理
 * @author jiangyaning
 * 
 *
 */
@Controller
public class CrctObjGradeController extends ABaseController {
    @Autowired
	
	private ICrctObjGradeService crctObjGradeService;	

	 //查询
	@RequestMapping("/get_CrctObjGrade_list")
	@ResponseBody
	public Resp get_CrctObjGrade_list( Integer pageIndex,
			Integer pageSize,HttpServletRequest request) {
		WebResp 	webResp = new WebResp();
	   CrctObjGradeVO CrctObjGradeVO=new  CrctObjGradeVO();
		webResp.setData(crctObjGradeService.getList(CrctObjGradeVO));
		webResp.setTotalCount(crctObjGradeService.getCount(CrctObjGradeVO));
	
		return webResp;
	}
	

	
	 //增加
	@RequestMapping("/save_CrctObjGrade")
	@ResponseBody
	public Resp save_CrctObjGrade(String name, String school_oid ,HttpServletRequest request) {
		WebResp 	webResp = new WebResp();
	   CrctObjGradeVO CrctObjGradeVO=new  CrctObjGradeVO();
	   CrctObjGradeVO.setName(name);
       CrctObjGradeVO.setSchool_oid(Long.parseLong(school_oid));
       CrctObjGradeVO.setCreate_date(new Date());
	  crctObjGradeService.save(CrctObjGradeVO);
		return webResp;
	}
	 //删除
	@RequestMapping("/remove_CrctObjGrade")
	@ResponseBody
	public Resp remove_CrctObjGrade(Long id,HttpServletRequest request) {
		WebResp 	webResp = new WebResp();
		CrctObjGradeVO CrctObjGradeVO=new  CrctObjGradeVO();
		crctObjGradeService.remove(id);
		return webResp;
	}
	
	 
    //基于角色
	 //增加
	@RequestMapping("/save_CrctObjGrade_school")
	@ResponseBody
	public Resp save_CrctObjGrade(String name,HttpServletRequest request) {
		WebResp 	webResp = new WebResp();
	   CrctObjGradeVO CrctObjGradeVO=new  CrctObjGradeVO();
	   CrctObjGradeVO.setName(name);
	   //从session获得当前学校ID
     //  CrctObjGradeVO.setSchool_oid(Long.parseLong(school_oid));
       CrctObjGradeVO.setCreate_date(new Date());
	  crctObjGradeService.save(CrctObjGradeVO);
		return webResp;
	}
//--------------------------------------------------------------------学校管理者
	 /**
	  * 学校管理者
	  * @param school_oid
	  * @return
	  */
	@RequestMapping("/get_CrctObjGrade_list_byschool")
	@ResponseBody
	public Resp get_CrctObjGrade_list_byschool(
			HttpServletRequest request) {
		WebResp 	webResp = new WebResp();
	   CrctObjGradeVO CrctObjGradeVO=new  CrctObjGradeVO();
	   String  school_oid = SessionManager.getsession(request).getSchool_oid();
	   CrctObjGradeVO.setSchool_oid(Long.parseLong(school_oid));
	    webResp.setData(crctObjGradeService.getList(CrctObjGradeVO));
	    webResp.setTotalCount(crctObjGradeService.getCount(CrctObjGradeVO));
	
		return webResp;
	}
	
	 //增加
	@RequestMapping("/save_CrctObjGrade_byschool")
	@ResponseBody
	public Resp save_CrctObjGrade_byschool(String name,HttpServletRequest request) {
		WebResp 	webResp = new WebResp();
	    try{
		CrctObjGradeVO CrctObjGradeVO=new  CrctObjGradeVO();
	   CrctObjGradeVO.setName(name);
	   String  school_oid = SessionManager.getsession(request).getSchool_oid();
	    CrctObjGradeVO.setSchool_oid(Long.parseLong(school_oid));
       CrctObjGradeVO.setCreate_date(new Date());
	  crctObjGradeService.save(CrctObjGradeVO);
	    } catch (Exception e) {
			e.printStackTrace();
			webResp.setRet(1);
			webResp.setErrcode(0);
			webResp.setMsg("增加失败！");
			return webResp;
		}
	  return webResp;
	}
	
	
	 /**
	  * 学校管理者获得一个
	  * @param school_oid
	  * @return
	  */
	@RequestMapping("/get_CrctObjGrade_one")
	@ResponseBody
	public Resp get_CrctObjGrade_one(Long oid,
			HttpServletRequest request) {
		WebResp 	webResp = new WebResp();
	   CrctObjGradeVO crctObjGradeVO=new  CrctObjGradeVO();
	   webResp.setData(crctObjGradeService.get(oid));
	  return webResp;
	}
	 /**
	  * 学校管理者修改年纪
	  * @param school_oid
	  * @return
	  */
	@RequestMapping("/update_CrctObjGrade_one")
	@ResponseBody
	public Resp update_CrctObjGrade_one( Long oid,String name,
			HttpServletRequest request) {
		WebResp 	webResp = new WebResp();
		CrctObjGradeVO  crctObjGradeVO	=crctObjGradeService.get(oid);
		crctObjGradeVO.setName(name);
		crctObjGradeService.save(crctObjGradeVO);


		return webResp;
	}
	

}
